package com.cj.service.impl;

import com.cj.dao.ClassDao;
import com.cj.po.Class;
import com.cj.po.PageInfo;
import com.cj.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("classService")
@Transactional
public class ClassServiceImpl implements ClassService {
    @Autowired
    private ClassDao classDao;

    // 分页查询
    @Override
    public PageInfo<Class> findPageInfo(String c_classid, String c_classname, String c_counsellor, Integer pageIndex, Integer pageSize) {
        PageInfo<Class> pi = new PageInfo<>();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        // 获取总条数
        Integer totalCount = classDao.totalCount(c_classid, c_classname, c_counsellor);
        if (totalCount > 0) {
            pi.setTotalCount(totalCount);
            // 每一页显示班级信息数
            List<Class> classList = classDao.getClassList(c_classid, c_classname, c_counsellor, (pi.getPageIndex() - 1) * pi.getPageSize(), pi.getPageSize());
            pi.setList(classList);
        }
        return pi;
    }

    @Override
    public List<Class> getAllClasses() {
        List<Class> classList = classDao.getAllClasses();
        return classList;
    }

    // 通过id删除班级信息
    @Override
    public int deleteClass(Integer c_id) {
        return classDao.deleteClass(c_id);
    }

    // 添加班级信息
    @Override
    public int addClass(Class clazz) {
        return classDao.addClass(clazz);
    }

    // 修改班级信息
    @Override
    public int updateClass(Class clazz) {
        return classDao.updateClass(clazz);
    }

    @Override
    public Class findClassById(Integer c_id) {
        Class clazz = classDao.findClassById(c_id);
        return clazz;
    }
}
